package com.qianfeng.wuyang.himalaya.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.qianfeng.wuyang.himalaya.R;
import com.qianfeng.wuyang.himalaya.adapter.recommendfocusadapter.CircleTransformation;
import com.qianfeng.wuyang.himalaya.adapter.recommendfocusadapter.RecomendFocusAdaprer;
import com.qianfeng.wuyang.himalaya.adapter.recommendfocusadapter.RecommendFocusCommentAdapter;
import com.qianfeng.wuyang.himalaya.bean.recommendfocusbean.Associationalbumsinfo;
import com.qianfeng.wuyang.himalaya.bean.recommendfocusbean.ListFocus;
import com.qianfeng.wuyang.himalaya.bean.recommendfocusbean.RecommendFocusOneBean;
import com.qianfeng.wuyang.himalaya.callback.RecommendFocusService;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RecommendedFocusActivity extends AppCompatActivity implements Callback<RecommendFocusOneBean> {


    private TextView textView,recommendedFocusTextView,recommendedFocusTextViewBy;
    private  RecommendFocusOneBean body;
    private ImageView RecomendedFocusImage,recommendedFocusAlbumInfo,recommendedFocusImageview;
    private TextView recommendedFocusText,recommendedFocusGZ;
    private ListView recommendedFocusListview,recommendedFocusCommentListview;
    private List<Associationalbumsinfo> list;
    private RecomendFocusAdaprer adaprer;
    private List<List<ListFocus>> lists;
     private RecommendFocusCommentAdapter commentAdapter;
    private  String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommended_focus);


        Intent intent=getIntent();
        id=intent.getStringExtra("id");
//        Log.d("number1620", "onCreate: "+id);



     Retrofit retrofit=new Retrofit.Builder()
            .baseUrl("http://mobile.ximalaya.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();
        RecommendFocusService focusService= retrofit.create(RecommendFocusService.class);
        focusService.getList(id).enqueue(this);


 }

 private void initView() {
        textView= (TextView) findViewById(R.id.recommendedFocusTitle);

//         Log.d("1620", "initView: " + body.getTrackInfo().getTitle());
         textView.setText(body.getTrackInfo().getTitle());
         RecomendedFocusImage = (ImageView) findViewById(R.id.recommendedFocusImage);
         Picasso.with(this)
                 .load(body.getUserInfo().getSmallLogo())
                 .transform(new CircleTransformation())
                 .into(RecomendedFocusImage);
         recommendedFocusText = (TextView) findViewById(R.id.recommendedFocusText);
         recommendedFocusText.setText(body.getUserInfo().getNickname());
         recommendedFocusAlbumInfo = (ImageView) findViewById(R.id.recommendedFocusAlbumInfo);

         Picasso.with(this)
                 .load(body.getAlbumInfo().getCoverLarge())
                 .into(recommendedFocusAlbumInfo);
         recommendedFocusImageview = (ImageView) findViewById(R.id.recommendedFocusImageview);
         Picasso.with(this)
                 .load(body.getAlbumInfo().getCoverMiddle())
                 .into(recommendedFocusImageview);
         recommendedFocusTextView = (TextView) findViewById(R.id.recommendedFocusTextView);
         recommendedFocusTextView.setText(body.getAlbumInfo().getTitle());
         recommendedFocusTextViewBy = (TextView) findViewById(R.id.recommendedFocusTextViewBy);
         recommendedFocusTextViewBy.setText("by:" + body.getUserInfo().getNickname());
         recommendedFocusGZ = (TextView) findViewById(R.id.recommendedFocusGZ);
      // recommendedFocusGZ.setText(body.getAlbumInfo().getAlbumId());
     recommendedFocusListview= (ListView) findViewById(R.id.recommendedFocusListview);

     recommendedFocusCommentListview= (ListView) findViewById(R.id.recommendedFocusCommentListview);
     adaprer=new RecomendFocusAdaprer(list,this);
     recommendedFocusListview.setAdapter(adaprer);
     commentAdapter=new RecommendFocusCommentAdapter(lists,this);
     recommendedFocusCommentListview.setAdapter(commentAdapter);

         }

    @Override
    public void onResponse(Call<RecommendFocusOneBean> call, Response<RecommendFocusOneBean> response) {
        list= new ArrayList<>();
        lists=new ArrayList<>();
        body=response.body();
//        Log.i("response.body()",response.body()+"123");
        list.add(body.getAssociationAlbumsInfo().get(0));
        list.add(body.getAssociationAlbumsInfo().get(1));
        list.add(body.getAssociationAlbumsInfo().get(2));

        lists.add(body.getCommentInfo().getList());
//        lists.add(body.getCommentInfo().getList().get(1));
//        lists.add(body.getCommentInfo().getList().get(2));
//        lists.add(body.getCommentInfo().getList().get(3));
//        lists.add(body.getCommentInfo().getList().get(4));

       initView();
      }

    @Override
    public void onFailure(Call<RecommendFocusOneBean> call, Throwable t) {
        t.printStackTrace();
        Toast.makeText(this, t.getMessage(), Toast.LENGTH_LONG).show();
    }


}
